<template>
  <!--项目计划信息  -->
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      formType="edit"
      :labelWidth="150"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { formatdateByDay } from '@/utils';
export default {
  mixins: [dictionary],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {}
    };
  },
  mounted() {
    console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    //日期格式化年月
    formatDatesNoDay: function(value) {
      // 这里的 value 就是需要过滤的数据
      if (value == null || value == '') {
        return '';
      }
      var date = new Date(value);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      return year + '-' + month;
    },
    init() {
        this.initForm.forEach(x => {
          x.initialValue = this.value.row[x.fieldName];
          if (x.fieldName == 'activityMonth') {
            x.initialValue = formatdateByDay(this.value.row.activityMonth);
          }
          if (x.fieldName == 'planBoothAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'planBuildAmount') {
            if (x.initialValue == null) {
              x.initialValue = '';
            }
          }
          if (x.fieldName == 'planDesc') {
              this.initForm.find(x=>x.fieldName == "planDesc").disabled = false;
          }
          if (x.fieldName == 'isChangePlan') {
              this.initForm.find(x=>x.fieldName == "isChangePlan").disabled = false;
          }

           
        });
    },
    //搜索数据
    initFormFun() {
      return [
        {
          type: 'TEXT_AREA',
          label: '项目名称',
          fieldName: 'projectName',
          initialValue: '',
          disabled: true,
          placeholder: ''
        },
        {
          type: 'TEXT_AREA',
          label: '项目介绍（项目描述）',
          fieldName: 'projectDesc',
          initialValue: '',
          disabled: true,
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '项目车型',
          fieldName: 'modelLists',
          selfCols:2,
          initialValue: [],
          disabled: true,
          temList: [], //复选框数据源
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '场地',
          fieldName: 'projectDesc',
          initialValue: '',
          disabled: true,
          placeholder: ''
        },
        {
          type: 'SELECT',
          label: '合作方式',
          fieldName: 'cooperationMethod',
          initialValue: '',
          disabled: true,
          placeholder: '',
          itemList: this.createDictList('2532')
        },
        {
          type: 'INPUT',
          label: '计划开展/投放时间',
          fieldName: 'planLaunchReleaseTime',
          initialValue: '',
          selfCols:2,
          disabled: true
        },
        {
          type: 'DATE',
          label: '开始日期',
          fieldName: 'planStartDate',
          valueFormat: 'yyyy-MM-dd',
          disabled: true,
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'DATE',
          label: '结束日期',
          fieldName: 'planEndDate',
          valueFormat: 'yyyy-MM-dd',
          disabled: true,
          initialValue: '',
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '投放天数',
          fieldName: 'planTimeDay',
          initialValue: '',
          placeholder: '',
          disabled: true
        },
        { type: 'INPUT', label: '项目地点', fieldName: 'planProjectLocation', placeholder: '', initialValue: '', selfCols:1,disabled: true
        },
                          
        { type: 'INPUT', label: '展位计划金额', fieldName: 'planBoothAmount', disabled: true, placeholder: '单位（元）', initialValue: undefined,numberFormat:true
        },

        { type: 'INPUT_NUMBER', label: '目标集客数', fieldName: 'targetGuestsNum', placeholder: '数字', initialValue: undefined,
            disabled:true,
            precision:0,
            min:0,
            rules:[
            ],
            disabled: true
        },
        { type: 'INPUT', label: '搭建运营计划金额', fieldName: 'planBuildAmount', disabled: true, placeholder: '单位（元）', initialValue: undefined,numberFormat:true
        },
        { type: 'INPUT_NUMBER', label: '目标订单数', fieldName: 'targetOrderNum', placeholder: '数字', initialValue: undefined,
            disabled:true,
            precision:0,
            min:0,
            rules:[
            ],
            disabled: true
        },
        // { type: 'SELECT', label: '预算类别', fieldName: 'budgetType', placeholder: '请选择', initialValue: '', itemList: this.createDictList('8052'),
        //     rules: [
        //         {
        //         required: true,
        //         message: '必填',
        //         trigger: 'change'
        //         }
        //     ]
        // },
        
        { type: 'INPUT', label: '计划项目金额', fieldName: 'planProjectAmount', placeholder: '单位（元）', initialValue: undefined,numberFormat:true,
            disabled: true
        },
          { type: 'INPUT_NUMBER', label: '目标留档数', fieldName: 'targetRetentionNum', placeholder: '数字', initialValue: undefined,
            disabled:true,
            precision:0,
            min:0,
            rules:[
            ],
            disabled: true
        },
        
        
        { type: 'INPUT', label: '计划批准金额', fieldName: 'planApproveAmount', placeholder: '单位（元）', initialValue: undefined,   disabled:true,numberFormat:true,
        },
    
        {        
          type: 'SELECT',
          label: '是否变更报备',
          fieldName: 'isChangePlan',
          initialValue: '',
          
          placeholder: '请选择...',
          itemList: this.createDictList('1004'),
          selfCols:2,
          change: this.isAllChange,
          rules: [{ required: true, message: '请选择是否需要变更报备', trigger: 'change' }]
        },
        {
          type: 'TEXT_AREA',
          label: '报备描述',
          fieldName: 'planDesc',
          selfCols:2,
          initialValue: '',
          placeholder: '',
          maxlength: 1000,
          rules: [{ required: false, message: '请填加报备描述', trigger: 'blur' }]
        },
        { type: 'UPLOAD_FILE', label: '附件', fieldName: 'uploadFileList', initialValue: [] ,selfCols:2,

            upload: {
                actionUrl: '/api/file/oss/upload', //上传的地址
                // tipText: '支持PDF/JPG/PNG/RAR格式，单个文件最大100M',
                limit:0,
                max:1024*100,
                fileTypes:['jpg',  'png', 'pdf', 'rar','ppt','pptx']
            }
        }
      
      ];
    },
    saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
    },
    formChangeHandle(val) {
      this.formValue = val;
      this.$emit('formchange', this.formValue);

    }
  },
  created() {
    this.init();
  }
};
</script>
